var url = require("url");//引入url模块
//解析 URL
/*var urlInfo = url.parse('http://www.cnblogs.com/best/p/6204116.html?name=孤傲苍狼&age=29');
console.log(urlInfo);
console.log(urlInfo.query);
console.log(url.format(urlInfo));
console.log(url.resolve("http://www.cnblogs.com/", "best/p"));*/

//http://localhost:9999/news?aid=123&cid=3
var http=require('http');//引入http模块
http.createServer(function (req,res) {
    //设置 HTTP 头部，状态码是 200，文件类型是 html，字符集是 utf8
    res.writeHead(200,{"Content-Type":"text/html;charset=UTF-8"});
    console.log(req.url);//获取浏览器url输入的信息
    if(req.url != '/favicon.ico'){
        //var result = url.parse(req.url);
        //解析 URL
        var result=url.parse(req.url,true);  //第一个参数是地址    第二个参数是true的话表示把get传值转换成对象
        //console.log(result);
        console.log(result.query);
        console.log('aid='+result.query.aid);  /*获取url的get传值*/
        console.log('cid='+result.query.cid);
    }
    res.write('你好nodejs');
    res.end(); /*结束响应*/
}).listen(9999);
console.log('Server running at http://127.0.0.1:9999');